package sad;

import com.sun.org.apache.bcel.internal.generic.NEW;
import java.io.DataOutput;
import java.util.Scanner;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 9:13
 * @description:
 */
public class SadDaoTest {
  private static Scanner sc=new Scanner(System.in);


  private static SadDao dao=new SadDaoMap();

  public static void main(String[] args) {
    //欢迎界面
    while (true) {
      System.out.println("------欢迎光临------");
      System.out.println("1:保存");
      System.out.println("2:查询");
      System.out.println("3:查询全部");
      System.out.println("4:删除");
      System.out.println("5:退出");
      System.out.println("请输入你的选择：");
      String num = sc.nextLine();
      switch (num) {
        case "1":
          saveFace();
          break;
        case "2":
          queryFace();
          break;
        case "3":
          queryAllFace();
          break;
        case "4":
          deleteFace();
          break;
        case "5":
          System.out.println("欢迎下次光临！");
          System.exit(0);
          break;
        default:
          System.out.println("重新输入");
          break;
      }
    }
  }

  private static void deleteFace() {
    System.out.println("-----删除界面-----");
    System.out.println("请输入要删除的中文或英文");
    String name=sc.nextLine();
    dao.delete(name);

  }

  private static void queryAllFace() {
    System.out.println("-----查询所有界面-----");
    dao.queryAll();

  }

  private static void queryFace() {
    System.out.println("-----查询界面-----");
    String name=sc.nextLine();
    Sad d=dao.query(name);
    if (d==null){
      System.out.println("词典里没有该单词，还需要升级");
    }else {
      System.out.println(d);
    }

  }

  private static void saveFace() {
    System.out.println("-----保存界面-----");
    System.out.println("请输入id:");
    String ids=sc.nextLine();
    int id=Integer.parseInt(ids);
    System.out.println("请输入英文：");
    String English=sc.nextLine();
    System.out.println("请输入中文：");
    String chinese=sc.nextLine();
    System.out.println("请输入备注：");
    String comments=sc.nextLine();
    Sad d =new Sad(id,English,chinese,comments);
    dao.save(d);
  }

}
